We've talked a bit about some of the built-in math functions and features in R, but let's have one more look at a few of them:
Here's a quick example of each:
v <- c(-1,0,1,2,3,4,5)
abs(-2)
abs(v)
sum(v)
mean(v)
round(23.1231)
round(23.1231234,2)
Want more built-in math functions? Check out:
| Function | Description |
| abs(x) | absolute value |
| sqrt(x) | square root |
| ceiling(x) | ceiling(3.475) is 4 |
| floor(x) | floor(3.475) is 3 |
| trunc(x) | trunc(5.99) is 5 |
| round(x, digits=n) | round(3.475, digits=2) is 3.48 |
| signif(x, digits=n) | signif(3.475, digits=2) is 3.5 |
| cos(x), sin(x), tan(x) | also acos(x), cosh(x), acosh(x), etc. |
| log(x) | natural logarithm |
| log10(x) | common logarithm |
| exp(x) | e^x |
You can also check out the documentation for even more functions, like those related to statistics (we'll cover those later on).